package com.itcam.cm.product.controller;


import com.itcam.cm.model.dto.product.ProductSkuDto;
import com.itcam.cm.model.entity.product.Brand;
import com.itcam.cm.model.entity.product.Product;
import com.itcam.cm.model.entity.product.ProductSku;
import com.itcam.cm.model.vo.common.Result;
import com.itcam.cm.model.vo.product.ProductItemVo;
import com.itcam.cm.product.service.BrandService;
import com.itcam.cm.product.service.ProductService;
import com.itcam.cm.product.service.ProductSkuService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @Autowired
    ProductSkuService productSkuService;

    @GetMapping(value = "/{page}/{limit}")
    public Result<PageInfo<ProductSku>> findByPage(@PathVariable Integer page,
                                                   @PathVariable Integer limit,
                                                   ProductSkuDto productSkuDto) {
        PageInfo<ProductSku> pageInfo = productService.findByPage(page, limit, productSkuDto);
        return Result.ok(pageInfo) ;
    }


    @GetMapping("item/{skuId}")
    public Result<ProductItemVo> item(@PathVariable Long skuId) {
        ProductItemVo productItemVo = productService.item(skuId);
        return Result.ok(productItemVo);
    }

    @GetMapping("/auth/getSkuById/{skuId}")
    public ProductSku getSkuById(@PathVariable  Long skuId){
        ProductSku productSku = productSkuService.getSkuById(skuId);
        return productSku;
    }


}
